
import request from './request'

//登录

export const loginApi = (name, password) => {
  return request({
    url: `/users/login`, method: 'POST', data: {
      userName: name,
      password: password
    }
  })
}
export const findApi = (name) => {
  return request({
    url: `/users/findUserName`, method: 'POST', data: {
      userName: name
    }
  })
}
export const registerApi = (userName,password) => {
  return request({
    url: `/users/register`, method: 'POST', data: {
      userName: userName,
      password:password
    }
  })
}

export const brandApi = () => {
  return request({
    url: `/product/getBrand`, method: 'POST', data: {

    }
  })
}
export const categoryApi = () => {
  return request({
    url: `/product/getCategory`, method: 'POST', data: {

    }
  })
}
export const carouselApi = () => {
  return request({
    url: `/resources/carousel`, method: 'POST', data: {

    }
  })
}
export const hotproductApi = (id) => {
  return request({
    url: `/product/getHotProduct`, method: 'POST', data: {
      brandID: id
    }
  })
}
export const usecategoryidApi = (id, currentPages) => {
  return request({
    url: `/product/getProductByCategory`, method: 'POST', data: {
      categoryID: id,
      currentPage: currentPages,
      pageSize: 10
    }
  })
}
//根据品牌分类获取商品
export const usebrandidApi = (id, currentPages) => {
  return request({
    url: `/product/getProductBybrandid`, method: 'POST', data: {
      brandID: id,
      currentPage: currentPages,
      pageSize: 10
    }
  })
}
export const usebrandandcatidApi = (brandid, categoryid) => {
  return request({
    url: `/product/getProductBybrand`, method: 'POST', data: {
      brandID: brandid,
      categoryID: categoryid
    }
  })
}
//获取商品详情
export const productdetailsApi = (productid) => {
  return request({
    url: '/product/getDetails', method: 'POST', data: {
      productID: productid,
    }
  })
}

//获取店铺详情
export const branddetailsApi = (brandid) => {
  return request({
    url: '/product/Getbranddetail', method: 'POST', data: {
      brandID: brandid,
    }
  })
}
//获取店铺所有商品
export const brandproductApi = (brandid) => {
  return request({
    url: '/product/Getbrandproduct', method: 'POST', data: {
      brandID: brandid,
    }
  })
}
//根据搜索条件
export const searchproductApi = (keyword) => {
  return request({
    url: '/product/getProductBySearch', method: 'POST', data: {
      search: keyword,
      currentPage: 1,
      pageSize: 8
    }
  })
}

//获取所有商品
export const allproductApi = (index = 1) => {
  return request({
    url: '/product/getAllProduct', method: 'POST', data: {
      currentPage: index,
      pageSize: 10
    }
  })
}

//加入收藏
export const addloveApi = (userid, productid) => {
  return request({
    url: '/user/collect/addCollect', method: 'POST', data: {
      user_id: userid,
      product_id: productid,

    }
  })
}
//获取收藏商品
export const loveproductApi = (userid) => {
  return request({
    url: '/user/collect/getCollect', method: 'POST', data: {
      user_id: userid,
    }
  })
}

//加入购物车
export const addCartApi = (userid, productid, num) => {
  return request({
    url: '/user/shoppingCart/addShoppingCart', method: 'POST', data: {
      user_id: userid,
      product_id: productid,
      addnum: num
    }
  })
}

//获取购物车商品
export const CartproductApi = (userid) => {
  return request({
    url: '/user/shoppingCart/getShoppingCart', method: 'POST', data: {
      user_id: userid,
    }
  })
}

//更新购物车商品数量

export const updatecartnumApi = (userid, productid, num) => {
  return request({
    url: '/user/shoppingCart/updateShoppingCart', method: 'POST', data: {
      user_id: userid,
      product_id: productid,
      num: num,
    }
  })
}

//删除购物车商品 
export const deleteproductincartApi = (userid, productid) => {
  return request({
    url: '/user/shoppingCart/deleteShoppingCart', method: 'POST', data: {
      user_id: userid,
      product_id: productid,
    }
  })
}


//获取收货地址

export const getaddressApi = (userid) => {
  return request({
    url: '/user/address/getaddress', method: 'POST', data: {
      user_id: userid,
    }
  })
}


//增加收货地址

export const addaddressApi = (address, detail, phone, username, userid) => {
  return request({
    url: '/user/address/addaddress', method: 'POST', data: {
      address: address,
      detail: detail,
      phone: phone,
      name: username,
      user_id: userid,
    }
  })
}

//增加收货地址

export const deladdressApi = (userid, id) => {
  return request({
    url: '/user/address/deladdress', method: 'POST', data: {
      user_id: userid,
      id: id
    }
  })
}


//获取订单111

export const getorderApi = (userid) => {
  return request({
    url: '/user/order/getOrder', method: 'POST', data: {
      user_id: userid,
    }
  })
}

//插入订单

export const insertorderApi = (userid, product) => {
  return request({
    url: '/user/order/addOrder', method: 'POST', data: {
      user_id: userid,
      products: product
    }
  })
}

